//
//  SetUpLabel.m
//  bzjpush
//
//  Created by 亿拓普 on 16/11/1.
//  Copyright © 2016年 cocoa. All rights reserved.
//

#import "SetUpLabel.h"


@implementation SetUpLabel

+ (UILabel *)setUpLabelWithFont:(int)font colorStr:(NSString *)colorStr frame:(CGRect)frame text:(NSString *)text
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.font = [UIFont systemFontOfSize:font];
    label.textColor = [UIColor colorWithHexString:colorStr];
    label.text = text;
    
    return label;
}


+ (UILabel *)setUpParagraphLabelWithFont:(int)font colorStr:(NSString *)colorStr frame:(CGRect)frame rowPadding:(CGFloat)rowPadding text:(NSString *)text
{
    NSString *str = text;
    CGSize labelSize = [str sizeWithFont:[UIFont systemFontOfSize:font] maxW:frame.size.width];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, labelSize.width, labelSize.height)];
    label.numberOfLines = 0;
    label.font = [UIFont systemFontOfSize:font];
    label.textColor = [UIColor colorWithHexString:colorStr];
    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
    paragraph.lineBreakMode = NSLineBreakByWordWrapping;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:str];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:rowPadding];//调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [str length])];
    label.attributedText = attributedString;
    [label sizeToFit]; // 自动适配文字宽度
    label.textAlignment = NSTextAlignmentCenter;

    return label;
}

@end
